<?php if($action=="index") {?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="keywords" content="系统用户组列表">
  <meta name="description" content="系统用户组列表">
  <title>系统用户组列表</title>
   <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/css/common.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/js/themes/bootstrap/easyui.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/js/themes/icon.css" />
 
  <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/jquery.min.js"></script>
  <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/jquery.easyui.min.js"></script>
 <script type="text/javascript" src="<?php echo site_url(); ?>app/views/js/locale/easyui-lang-zh_CN.js"></script>

  <script type="text/javascript">
    var url;
    function newUser(){
     window.location.href="add";
    }
    function editUser(){
      var row = $('#dg').datagrid('getSelected');
      
      if (row){
         window.location.href='edit?id='+row.id;
      }else{
         $.messager.alert('提示','请选择要编辑的行！');
      }
    }
    function saveUser(){
      $('#fm').form('submit',{
        url: url,
        onSubmit: function(){
          return $(this).form('validate');
        },
        success: function(result){
          var result = eval('('+result+')');
          if (result.success){
            $('#dlg').dialog('close');    // close the dialog
            $('#dg').datagrid('reload');  // reload the user data
          } else {
            $.messager.show({
              title: 'Error',
              msg: result.msg
            });
          }
        }
      });
    }
    function removeUser(){
      var row = $('#dg').datagrid('getSelected');
      if (row){
        $.messager.confirm('确认提示','你确定要删除这个用户组？',function(r){
          if (r){
            $.post('del',{id:row.id},function(result){
              if (result.success){
                $('#dg').datagrid('reload');  // reload the user data
              } else {
                $.messager.show({ // show error message
                  title: 'Error',
                  msg: result.msg
                });
              }
            },'json');
          }
        });
      }else{
        $.messager.alert("提示","请选中要删除的行！");
      }
    }
  </script>
</head>
<body>
  <h2 class="navfont">系统用户组管理:</h2>
  

  <table id="dg" title="" class="easyui-datagrid" style="width:1100px;height:550px"
      url="get_group"
      toolbar="#toolbar" pagination="true"
      rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
      <tr>
        <th field="id" width="50">编号</th>
        <th field="name" width="50">用户组名称</th>
        
      </tr>
    </thead>
  </table>
  <div id="toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">新增</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">编辑</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeUser()">删除</a>
  </div>

 
  
</body>
</html>


<?php }elseif ($action=="add") {?>
<br><br>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>获取表单数据</title>

 <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/css/common.css" />
 
 
</head>
<body>
  <div class="demo-content">
<style>
	.table{width: 80%;height: auto;position: relative;left:10%;}


</style>

    <form action="<?php echo site_url() ?>index.php/group/adddb" onsubmit="return make_str()" method="post">   
    <input type="hidden" id="functions" name="functions" value="">
   <div class="row">	
<table class="table " >
<tr><td>用户组名称:</td><td><input name="name" type="text" class="input-large control-text" style="width:400px;height:30px"><br></td></tr>
  <?php foreach ($functions as $key => $value) {?>
 <tr>
        <td>
          <input type="checkbox" name="function" value="<?php echo $value['id'] ;?>">&nbsp;<?php echo $value['menu'] ?><?php if ($value['type'] == '1'){?>-(<span style='color:red'>菜单项</span>)<?php } ?>
        </td>
        <td>
         <table class="table">
         <?php foreach ($value['list'] as $key2 => $value2) {?>
         	 <tr>
             <td>
            <input type="checkbox" name="function" value="<?php echo $value2['id'] ?>">&nbsp;<?php echo $value2['menu'] ?><?php if($value2['type']==1){ ?>-(<span style='color:red'>菜单项</span>)<?php } ?>&nbsp;&nbsp;
            </td>
            <td>
            <?php foreach ($value2['list'] as $key3 => $value3) {?>
            	 <input type="checkbox" name="function" value="<?php echo $value3['id'] ?>">&nbsp;<?php echo $value3['menu'] ?><?php if($value3['type']==1){ ?>-(<span style='color:red'>菜单项</span>)<?php } ?>&nbsp;&nbsp;
            <?php } ?>
            </td>
       <?php  } ?>
          </tr>
          </table>

        </td>
          
      </tr>
  	
  <?php } ?>
<tr><td><button type="submit" class="button button-primary">保存用户组</button></td><td></td></tr>
</table>



   </div>



        <div class="row form-actions actions-bar">
            <div class="span13 offset10 ">
              
              
            </div>
        </div>
    </form>
    <div class="row">
     

    </div>
    
 
  <script src="<?php echo site_url(); ?>app/views/js/jquery.min.js"></script>
  <script>
  function make_str(){
  var id_array=new Array();
  $('input[name="function"]:checked').each(function(){
      id_array.push($(this).val());
  });
  var idstr=id_array.join('|');

  if($("#functions").val(idstr)){
     return true;
  }else{
    return false;
  }
  
}

</script>
  </div>
</body>
</html>




<?php
} elseif ($action=="edit") {?>
	<br><br>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>获取表单数据</title>

 <link rel="stylesheet" type="text/css" href="<?php echo site_url(); ?>app/views/css/common.css" />
 
 
</head>
<body>

  <div class="demo-content">

<style>
	.table{width: 80%;height: auto;position: relative;left:10%;}
  .table tr,td{border:solid 1px #CCC;}

</style>
    <form action="<?php echo site_url() ?>index.php/group/update" onsubmit="return make_str()" method="post">   
    <input type="hidden" id="functions" name="functions" value="">
    <input type="hidden" id="functions" name="id" value="<?php echo $id; ?>">
   <div class="row">	

<table class="table " >
<tr><td>用户组名称:</td><td><input name="name" type="text" class="input-large control-text" value="<?php echo $name ?>" style="width:400px;height:30px"><br></td></tr>
  <?php foreach ($functions as $key => $value) {?>
 <tr>
        <td>
          <input type="checkbox" name="function" <?php if($value['checked']=="true"){ ?>checked="checked"<?php } ?> value="<?php echo $value['id'] ;?>">&nbsp;<?php echo $value['menu'] ?><?php if ($value['type'] == '1'){?>-(<span style='color:red'>菜单项</span>)<?php } ?>
        </td>
        <td>
         <table class="table">
         <?php foreach ($value['list'] as $key2 => $value2) {?>
         	 <tr>
             <td>
            <input type="checkbox" name="function" value="<?php echo $value2['id'] ?>" <?php if($value2['checked']=="true"){ ?>checked="checked"<?php } ?>>&nbsp;<?php echo $value2['menu'] ?><?php if($value2['type']==1){ ?>-(<span style='color:red'>菜单项</span>)<?php } ?>&nbsp;&nbsp;
            </td>
            <td>
            <?php foreach ($value2['list'] as $key3 => $value3) {?>
            	 <input type="checkbox" name="function" value="<?php echo $value3['id'] ?>" <?php if($value3['checked']=="true"){ ?>checked="checked"<?php } ?>>&nbsp;<?php echo $value3['menu'] ?><?php if($value3['type']==1){ ?>-(<span style='color:red'>菜单项</span>)<?php } ?>&nbsp;&nbsp;
            <?php } ?>
            </td>
       <?php  } ?>
          </tr>
          </table>

        </td>
          
      </tr>
  	
  <?php } ?>
<tr><td><button type="submit" class="button button-primary">保存用户组</button></td><td></td></tr>

</table>



   </div>



    </form>
    <div class="row">
     

    </div>
    
 
  <script src="<?php echo site_url(); ?>app/views/js/jquery.min.js"></script>
  <script>
  function make_str(){
  var id_array=new Array();
  $('input[name="function"]:checked').each(function(){
      id_array.push($(this).val());
  });
  var idstr=id_array.join('|');

  if($("#functions").val(idstr)){
     return true;
  }else{
    return false;
  }
  
}

</script>
  </div>
</body>
</html>


<?php
} ?>
